/** 
* All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
* 
* BaseFlowFileService
* 流程文件
* 
* 修改纪录
* 2021-01-14 版本：1.0 lishuming 创建。
* @version 版本：1.0
* @author 作者：lishuming
* 创建日期：2021-01-14
*/
package com.topscomm.base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.base.BaseSystemConst;
import com.topscomm.base.pojo.BaseFlowFileEntity;
import com.topscomm.base.service.IBaseFlowFileService;
import com.topscomm.base.service.impl.auto.BaseFlowFileServiceAuto;
import com.topscomm.basic.BasicEntity;
import com.topscomm.basic.exception.ServiceException;
import com.topscomm.basic.util.PrimaryKeyUtil;
import com.topscomm.dsp.api.DspServiceApi;
import com.topscomm.pub.util.BaseUtil;
import com.topscomm.pub.vo.Page;

@Service(value = "baseFlowFileService")
@Scope(value = "singleton")
public class BaseFlowFileService extends BaseFlowFileServiceAuto implements IBaseFlowFileService {
	@Autowired
	private DspServiceApi dspServiceApi;

	/**
	 * 
	 * @description:新增前处理
	 * @auther: wanghanwei
	 * @date: 2021年1月13日下午6:34:36
	 * @modify:
	 */
	@Override
	protected void beforeInsert(BasicEntity entity) throws ServiceException {
		super.beforeInsert(entity);// 赋值code
		if (entity.getId() <= 0) {// 赋值Id和单号
			long[] arrayId = PrimaryKeyUtil.GeneIDs(entity.getTableName(), 1);
			entity.setId(arrayId[0]);
			String code = String.valueOf(arrayId[0]);
			code = BaseSystemConst.MCR_FILE_CODE + code.substring(0, 6) + code.substring(9);
			entity.setValue(BaseFlowFileEntity.FieldCode, code);
		}
	}

	/**
	 * @description:文件信息同步
	 * @author: lishuming
	 * @date: 2021年1月18日下午2:05:28
	 * @modify:
	 */
	@Override
	public void baseFlowFileSync() {
		// 从数据接口获取文档中心公司流程最新版本文件
		String templateid = "MCRQueryOADM";
		Map<String, Object> paraMap = new HashMap<>();
		paraMap.put("pageSize", "0");// 返回所有记录
		paraMap.put("pageNum", "1");
		Page page = dspServiceApi.query(templateid, paraMap);
		List<Map<String, Object>> dataList = (List<Map<String, Object>>) page.getDataList();
		List<Map<String, Object>> lowerKeyDataList = BaseUtil.lowerKey(dataList);
		// 文件更新
		if (lowerKeyDataList.size() > 0) {
			this.updateBatchMap(lowerKeyDataList, "updateFileMap");
		}
	}

}
